//
//  MYGlobal.m
//  PetExchange
//
//  Created by a on 2020/12/17.
//

#import "MYGlobal.h"

//水印存储路径
#define shuiyinPath [NSString stringWithFormat:@"%@/Documents/init.txt",NSHomeDirectory()]
@implementation MYGlobal
+(MYGlobal *)share{
    static MYGlobal *sharedGlobalInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedGlobalInstance = [[self alloc] init];
    });
    return sharedGlobalInstance;
}

-(id)init{
    self=[super init];
    if (self) {
        self.shenHeFlag = 0;
        self.vip_expiry = [DWKeychainTool getItemForKey:@"id"];
    }
    self.language = [[NSLocale preferredLanguages] firstObject];
    DLog(@"当前系统语言: %@", self.language);
    if([self.language containsString:@"zh"]){
        
    }
    return self;
}

- (void)saveData{
    
}
//保存数据
-(void)saveDataWithDict:(NSDictionary *)dict  withPath:(NSString *)path{
    //DLog(@"dict===%@",dict);
    if (dict == nil) {
        return;
    }
    NSData *resultData= [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSFileManager *fm=[NSFileManager defaultManager];
    if (![fm fileExistsAtPath:path]) {
        [fm createFileAtPath:path contents:nil attributes:nil];
    }
    [resultData writeToFile:path atomically:YES];
}
//得到数据
-(NSMutableDictionary *)getDataWithPath:(NSString *)path{
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSMutableDictionary *dict;
    if (data) {
        dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:nil];
    }else{
        dict = [[NSMutableDictionary alloc] init];
    }
    return dict;
}

- (BOOL)isVip{
    
    if(self.vip_expiry == nil  || self.vip_expiry.length < 2){
        return NO;
    }
    if([Helper validateWithStartTime:@"2022-11-09 17:00:00" withExpireTime:self.vip_expiry]){
        return YES;
    }
    return NO;
}

- (void)setVip_expiry:(NSString *)vip_expiry{
    _vip_expiry = vip_expiry;
    [DWKeychainTool saveItem:_vip_expiry key:@"vipTime"];
}

@end
